$(function () {

    var idSelect = $('#id').select2();

    idSelect.on("select2:select", function (evt) {
        //这里是选中触发的事件
        //id: "1"
        //text: "alyssayang(杨洋)"
        var data = evt.params.data;
        var id = data.id;

        $.get('/api/luck/get?id=' + id, function (res) {
            var one = res.data;
            console.log("选中:" + id + "," + one);
            $('#place').val(one.city);
        });

    });

    // IOS 微信浏览器开启点击事件
    $("body>*").bind("click", function () {
    });

    $('#goLuck').on('click', function () {
        var id = $('#id').val();

        $.get('/api/luck/chou?id=' + id, function (res) {
            var city = res.data.city;

            $('#place').val(city);

            var url = ""

            if (res.success === true) {
                console.log(res)
                if ("成都" === city) {
                    url = "/ticket_chengdu";
                } else if ("重庆" === city) {
                    url = "/ticket_chongqing"
                } else if ("南京" === city) {
                    url = "/ticket_nanjing"
                } else if ("南昌" === city) {
                    url = "/ticket_nanchang"
                } else if ("武汉" === city) {
                    url = "/ticket_wuhan"
                } else {
                    url = "/ticket_online"
                }

                window.location.href = url;
            } else {
                var url = "/ticket_online"
                window.location.href = url;
            }
        });
    });
})